//-----------------------------------------------------------------------------
// Name: BoundingManager.cpp
// Auth: Rob Darty & Paul Godfrey
// Desc: Keeps a list of BoundingBoxes
//-----------------------------------------------------------------------------


#include "BoundingManager.h"
#include "Bounding.h"
#include <iostream>
#include <windows.h>
#include <list>
using namespace std;
cBoundingManager gBoundingManager;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cBoundingManager* GetBoundingManager()
{
	return &gBoundingManager;
}

cBoundingManager::cBoundingManager()
{

}

cBoundingManager::~cBoundingManager()
{
}

//Adds one boundingbox to the manager - queue position is irrelevent so it always adds to the back.
void cBoundingManager::addBounding(float minX, float maxX, float minY, float maxY, 
															 float minZ, float maxZ )
{
	cBoundingManager* pBoundingManager = GetBoundingManager();
	
	cBounding* newBounding = new cBounding( minX, maxX, minY, maxY, minZ, maxZ );

	(*pBoundingManager).liBounding.push_back(*newBounding);

}

//Removes 1 boundingbox from the list if that object has reached the end of its life 
void cBoundingManager::removeBounding()
{
	if(!(liBounding.empty()))
	{
		itBound=liBounding.begin();
		while(itBound!=liBounding.end())
		{
			cBounding *pBounding = &*itBound;

			bool test = pBounding->getStatus();

			if(test==false)
			{
				liBounding.erase(itBound);
				break; //TODO: is it possible to remove this and have it work???
			}
			if(itBound!=liBounding.end())
			{
				itBound++;
			}
		}
	}

}
